package com.ruoyi.room.service.impl;

import java.util.List;

import com.ruoyi.apartment.mapper.HumanApartmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.room.mapper.HumanRoomMapper;
import com.ruoyi.room.domain.HumanRoom;
import com.ruoyi.room.service.IHumanRoomService;

/**
 * 房间属性管理Service业务层处理
 * 
 * @author leo
 * @date 2024-10-11
 */
@Service
public class HumanRoomServiceImpl implements IHumanRoomService 
{
    @Autowired
    private HumanRoomMapper humanRoomMapper;
    @Autowired
    private HumanApartmentMapper humanApartmentMapper;
    /**
     * 查询房间属性管理
     * 
     * @param roomId 房间属性管理主键
     * @return 房间属性管理
     */
    @Override
    public HumanRoom selectHumanRoomByRoomId(Long roomId)
    {
        return humanRoomMapper.selectHumanRoomByRoomId(roomId);
    }

    /**
     * 查询房间属性管理列表
     * 
     * @param humanRoom 房间属性管理
     * @return 房间属性管理
     */
    @Override
    public List<HumanRoom> selectHumanRoomList(HumanRoom humanRoom)
    {
        return humanRoomMapper.selectHumanRoomList(humanRoom);
    }

    /**
     * 新增房间属性管理
     * 
     * @param humanRoom 房间属性管理
     * @return 结果
     */
    @Override
    public int insertHumanRoom(HumanRoom humanRoom)
    {
        // 如果提供了公寓昵称但没有公寓ID，根据昵称查找ID
        if (humanRoom.getApartmentNickname() != null && humanRoom.getApartmentId() == null) {
            Long apartmentId = humanApartmentMapper.selectApartmentIdByName(humanRoom.getApartmentNickname());
            humanRoom.setApartmentId(apartmentId);
        }
        return humanRoomMapper.insertHumanRoom(humanRoom);
    }

    /**
     * 修改房间属性管理
     * 
     * @param humanRoom 房间属性管理
     * @return 结果
     */
    @Override
    public int updateHumanRoom(HumanRoom humanRoom)
    {
        if (humanRoom.getApartmentNickname() != null && humanRoom.getApartmentId() == null) {
            Long apartmentId = humanApartmentMapper.selectApartmentIdByName(humanRoom.getApartmentNickname());
            humanRoom.setApartmentId(apartmentId);
        }
        return humanRoomMapper.updateHumanRoom(humanRoom);
    }

    /**
     * 批量删除房间属性管理
     * 
     * @param roomIds 需要删除的房间属性管理主键
     * @return 结果
     */
    @Override
    public int deleteHumanRoomByRoomIds(Long[] roomIds)
    {
        return humanRoomMapper.deleteHumanRoomByRoomIds(roomIds);
    }

    /**
     * 删除房间属性管理信息
     * 
     * @param roomId 房间属性管理主键
     * @return 结果
     */
    @Override
    public int deleteHumanRoomByRoomId(Long roomId)
    {
        return humanRoomMapper.deleteHumanRoomByRoomId(roomId);
    }
}
